package com.dykj.fireFighting.web.base.news;

import com.dykj.fireFighting.api.base.news.entity.SmsReport;
import com.dykj.fireFighting.api.base.news.entity.VoiceCallReport;
import com.dykj.fireFighting.api.base.news.entity.VoiceRepor;
import com.dykj.fireFighting.api.base.news.service.IAliMessageService;
import com.dykj.fireFighting.common.core.annotation.AutoLog;
import com.dykj.fireFighting.common.core.api.AliReport;
import com.dykj.fireFighting.common.core.api.CommonResult;
import com.netflix.client.http.HttpRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;

@Slf4j
@Api(value = "阿里短信语音回调接口", tags = {"阿里短信语音回调接口"})
@RestController
@RequestMapping("/ts/a")
public class AliReportController {

    @DubboReference
    private IAliMessageService aliMessageService;

    /**
     * 短信发送是否成功回调
     */
    @AutoLog(value = "短信回调")
    @ApiOperation(value = "短信回调", notes = "短信回调")
    @PostMapping("/smsReport")
    public CommonResult getSmsReport(@RequestBody List<SmsReport> smsReportList) {
        for (SmsReport smsReport : smsReportList) {
            aliMessageService.updateAliMessage(smsReport.getErr_msg(), smsReport.getBiz_id());
        }
        return CommonResult.success("成功");
    }

    /**
     * 短信发送是否成功回调
     */
    @AutoLog(value = "语音回调")
    @ApiOperation(value = "语音回调", notes = "语音回调")
    @PostMapping("/voiceCallReport")
    public AliReport getVoiceCallReport(@RequestBody List<VoiceRepor> voiceCallReportList) {
        for (VoiceRepor voiceCallReport : voiceCallReportList) {
            aliMessageService.updateAliVoiceCall(voiceCallReport.getStatus_code(), voiceCallReport.getCall_id());
        }
        AliReport aliReport = new AliReport();
        aliReport.setCode(0);
        aliReport.setMsg("成功");
        return aliReport;
    }



    /**
     * 短信发送是否成功回调
     */
    /*@AutoLog(value = "语音回调")
    @ApiOperation(value = "语音回调", notes = "语音回调")
    @PostMapping("/voiceCallReport")
    public AliReport check() {
        AliReport aliReport = new AliReport();
        aliReport.setCode(0);
        aliReport.setMsg("成功");
        return aliReport;
    }*/
}
